package approve.action;

import nguyen.dao.ReceiverDocumentDAO;
import model.pojo.Document;
import model.pojo.DocumentDetail;
import model.pojo.Employee;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.EditText;
import android.widget.TextView;

public class Re_ViewForm15 extends Activity {
	// component
	TextView la_title, la_description, la_content, la_location, la_peforment,
			la_datetrip, la_totaltime, la_totalamount, la_comment;

	EditText title, description, location, performent, dateTrip, totalTime,
			totalAmount, comment;
	WebView content;
	TextView la_createDate, la_writer, re_createDate;
	EditText re_employee;
	// bundle
	Document doc = null;
	String database = "admin";
	String lang = "EN";
	Bundle language = null;
	Employee emp = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.re_viewform15);
		getComponent();

		loadBunlde();
		loadLanguage();

		viewDocument();

	}

	private void getComponent() {
		la_createDate = (TextView) findViewById(R.id.la_createDate);
		la_writer = (TextView) findViewById(R.id.la_writer);
		re_createDate = (TextView) findViewById(R.id.re_createDate);
		re_employee = (EditText) findViewById(R.id.re_employee);

		la_title = (TextView) findViewById(R.id.la_title);
		la_description = (TextView) findViewById(R.id.la_description);
		la_content = (TextView) findViewById(R.id.la_content);
		la_location = (TextView) findViewById(R.id.la_location);
		la_peforment = (TextView) findViewById(R.id.la_peforment);
		la_datetrip = (TextView) findViewById(R.id.la_datetrip);
		la_totaltime = (TextView) findViewById(R.id.la_totaltime);
		la_totalamount = (TextView) findViewById(R.id.la_totalamount);
		la_comment = (TextView) findViewById(R.id.la_comment);

		title = (EditText) findViewById(R.id.re_viewform12_title);
		description = (EditText) findViewById(R.id.re_viewform12_description);
		location = (EditText) findViewById(R.id.re_viewform12_location);
		performent = (EditText) findViewById(R.id.re_viewform12_performent);
		dateTrip = (EditText) findViewById(R.id.re_viewform12_datetrip);
		totalTime = (EditText) findViewById(R.id.re_viewform12_totaltime);
		totalAmount = (EditText) findViewById(R.id.total_amount);
		content = (WebView) findViewById(R.id.re_viewform12_content);
		comment = (EditText) findViewById(R.id.comment);
	}

	private void loadBunlde() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			database = extras.getString("database");
			lang = extras.getString("lang");
			emp = (Employee) extras.get("em");
			doc = (Document) extras.get("doc");
			language = extras.getBundle(lang);

		}
	}

	private void loadLanguage() {
		if (language != null) {
			la_createDate.setText(language.getString("created-date") + ": ");
			la_writer.setText(language.getString("writer") + "/"
					+ language.getString("Department"));

			la_title.setText(language.getString("title"));
			la_description.setText(language.getString("Description"));
			la_content.setText(language.getString("content"));

			la_location.setText(language.getString("where"));
			la_peforment.setText(language.getString("implementation"));
			dateTrip.setText(language.getString("trip_date"));
			totalTime.setText(language.getString("total_time"));

			la_totalamount.setText(language.getString("ac_lien_SThanhTien"));
			la_comment.setText(language.getString("comment"));
		}
	}

	private void viewDocument() {
		if (doc != null) {
			re_createDate.setText(doc.getTimecreate() + "");
			re_employee.setText(doc.getEmployeeName() + "/"
					+ doc.getDepartment());

			title.setText(doc.getTitle());

			description.setText(doc.getDescription());

			final String mimeType = "text/html";
			String header = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
			content.loadData(header + doc.getContent(), mimeType, null);

			// DocumentDetail
			// doc_detail=ReceiverDocumentDAO.getDocumentDetailForm15(database,
			// doc.getId());
			// if(doc_detail!=null){
			location.setText(doc.getLocation());
			performent.setText(doc.getEmployeePerforment());
			dateTrip.setText(doc.getDateTrip() + "");
			totalTime.setText(doc.getTimecreate() + "");
			comment.setText(doc.getComment());

			totalAmount.setText(ReceiverDocumentDAO.getTotalAmount(database,
					doc.getId()) + "");
			// }
		}
	}
}
